package www.test.tag;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class IPTag extends TagSupport
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	public int doStartTag() throws JspException
	{
		
		
		
		
		/*HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
		JspWriter out =this.pageContext.getOut();
		InetAddress addr = null;
		try
		{
			addr = InetAddress.getLocalHost();
		}
		catch (UnknownHostException e1)
		{
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String ip =addr.getHostAddress().toString();
		String name =addr.getHostName().toString(); 
		try
		{
			out.println("ip："+ip+"</br>");
			out.println("主机名："+name);
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		*/
		
		
		//HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
		JspWriter out = this.pageContext.getOut();
		InetAddress addr =null;
		
		String ip;
		try
		{
			addr =InetAddress.getLocalHost();
			ip = addr.getHostAddress().toString();
			String name = addr.getCanonicalHostName().toString();
			out.print("ip:"+ip+"</br>");
			out.print("主机名："+name);
		}
		catch (UnknownHostException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
 		return super.doStartTag();
	}

}
